package com.nightsoul.hadoop1.test.hdfs;

import java.io.InputStream;
import java.net.URI;
import java.net.URL;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.junit.Test;

public class UrlCat {
	
	@Test
	public void test() throws Exception {
		//该方法只能在虚拟机中调用一次
		URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
		URL url = new URL("hdfs://192.168.0.203:10000/output_combiner/part-r-00000");
		
		InputStream inputStream = url.openStream();
		IOUtils.copy(inputStream, System.out);
		inputStream.close();
	}
	
	@Test
	public void testFileSystem() throws Exception {
		Configuration configuration = new Configuration();
		FileSystem fs = FileSystem.get(URI.create("hdfs://192.168.0.203:10000"), configuration);
		System.out.println(fs.getHomeDirectory());
	}
}
